USE [genshi]
GO

/****** Object:  Trigger [dbo].[Up_attribute]    Script Date: 2022/5/3 20:28:27 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER [dbo].[Up_attribute] ON [dbo].[Assemble]
After Insert
AS
Begin
	SET NOCOUNT ON;
	Declare @property nvarchar(10);
	Declare @value real;
	Declare @Name nvarchar(10);
	select @property = Character.Properties from Character,inserted where inserted.Name = Character.Name
	select @value = Character.Value from Character,inserted where inserted.Name = Character.Name
	select @Name = inserted.Name from inserted;
	update Assemble
	set Life = Life + (select Character.Life from Character, inserted where  inserted.Name = Character.Name)
	where Assemble.Name = @Name;
	update Assemble
	set Attack = Attack + (select Character.Attack from Character, inserted where  inserted.Name = Character.Name)
	where Assemble.Name = @Name;
	update Assemble
	set Defense = Defense + (select Character.Defense from Character, inserted where  inserted.Name = Character.Name)
	where Assemble.Name = @Name;

	if (@property = '生命值')
		begin
				update Assemble
				set LifePercentage = LifePercentage + @value
				where Assemble.Name = @Name;
		end
	else if(@property = '攻击力')
		begin 
				update Assemble
				set AttackPercentage = AttackPercentage + @value
				where Assemble.Name = @Name;
		end
	else if(@property = '防御力')
		begin
				update Assemble
				set DefensePercentage = DefensePercentage + @value
				where Assemble.Name = @Name;
		end
	else if(@property = '元素精通')
		begin
			update Assemble
			set Mystery = Mystery + @value
			where Assemble.Name = @Name;
		end
	else if(@property = '暴击率')
		begin
			update Assemble
			set Criticalhit = Criticalhit + @value
			where Assemble.Name = @Name;
		end
	else if(@property = '暴击伤害')
		begin
			update Assemble
			set Criticaldamage = Criticaldamage + @value
			where Assemble.Name = @Name;
		end	
	else if(@property = '治疗加成')
		begin
			update Assemble
			set Treatment = Treatment + @value
			where Assemble.Name = @Name;
		end	
	else if(@property = '元素充能效率')
		begin
			update Assemble
			set Efficiency = Efficiency + @value
			where Assemble.Name = @Name;
		end
	else if(@property = '火元素伤害加成')
		begin
			update Assemble
			set Fire = Fire + @value
			where Assemble.Name = @Name;
		end
	else if(@property = '水元素伤害加成')
		begin
			update Assemble
			set Water = Water + @value
			where Assemble.Name = @Name;
		end
	else if(@property = '雷元素伤害加成')
		begin
			update Assemble
			set Thunder = Thunder + @value
			where Assemble.Name = @Name;
		end
	else if(@property = '风元素伤害加成')
		begin
			update Assemble
			set Wind = Wind + @value
			where Assemble.Name = @Name;
		end
	else if(@property = '冰元素伤害加成')
		begin
			update Assemble
			set Ice = Ice + @value
			where Assemble.Name = @Name;
		end
	else if(@property = '岩元素伤害加成')
		begin
			update Assemble
			set Rock = Rock + @value
			where Assemble.Name = @Name;
		end
	else if(@property = '物理伤害加成')
		begin
			update Assemble
			set Physics = Physics + @value
			where Assemble.Name = @Name;
		end
End
GO

ALTER TABLE [dbo].[Assemble] ENABLE TRIGGER [Up_attribute]
GO

